package com.dcbdemo.springbootvuedemo.controller;

import com.alibaba.fastjson.JSON;
import com.dcbdemo.springbootvuedemo.domain.MainMenu;
import com.dcbdemo.springbootvuedemo.mapper.MenuDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2021/7/13 17:44
 */
@RestController
public class MenuController {
    @Autowired
    MenuDao menuDao;

    @CrossOrigin
    @RequestMapping("/menus")
    public String getAllMenus(){
        HashMap<String, Object> data = new HashMap<>();
        List<MainMenu> mainMenus = menuDao.getMainMenus();
        if(mainMenus !=null){
            data.put("data",mainMenus);
            data.put("status",200);
        }else{
            data.put("status",404);
        }
        System.out.println(data);
        String data_json = JSON.toJSONString(data);
        System.out.println(data_json);
        System.out.println(JSON.toJSONString(mainMenus));
        System.out.println("成功访问！！！");
        return data_json;
    }
}
